﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class MaritalStatusBO : BaseBO
    {
        public const string FIELD_MARITAL_STATUS_ID = "Marital_Status_Id";
        public const string FIELD_CODE = "Code";
        public const string FIELD_NAME = "Name";
        public const string FIELD_DELETED = "Deleted";
        public const string FIELD_DESCRIPTIONS = "Descriptions";
        public const string FIELD_RECORD_COUNT = "RecordCount";

        private String _connectionString;
        
        public MaritalStatusBO(string connString)
        {
            this._connectionString = connString;
        }
        public MaritalStatusBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;
        }

        public MaritalStatusDAO _maritalStatusDAO;

        public MaritalStatusDAO CreateSQLDAO()
        {
            return new MaritalStatusDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<MaritalStatusModel> GetDynamicListPaging(MaritalStatusModel msModel, int pSize, int pIndex)
        {
            try
            {
                _maritalStatusDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {MaritalStatusModel.FIELD_MARITAL_STATUS_ID,FIELD_MARITAL_STATUS_ID},
                    {MaritalStatusModel.FIELD_CODE,FIELD_CODE},
                    {MaritalStatusModel.FIELD_NAME,FIELD_NAME},
                    {MaritalStatusModel.FIELD_DELETED,FIELD_DELETED},
                    {MaritalStatusModel.FIELD_RECORD_COUNT,FIELD_RECORD_COUNT}
                    
                };
                return _maritalStatusDAO.GetDynamicListPaging(msModel, pSize, pIndex, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public MaritalStatusModel GetMaritalStatusById(string maritalStatusId)
        {
            try
            {
                _maritalStatusDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {MaritalStatusModel.FIELD_MARITAL_STATUS_ID,FIELD_MARITAL_STATUS_ID},
                    {MaritalStatusModel.FIELD_NAME,FIELD_NAME},
                    {MaritalStatusModel.FIELD_CODE,FIELD_CODE},  
                    {MaritalStatusModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},                    
                };

                return _maritalStatusDAO.GetById(maritalStatusId, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdate(MaritalStatusModel msModel)
        {
            try
            {
                _maritalStatusDAO = CreateSQLDAO();
                return _maritalStatusDAO.createOrUpdate(msModel);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteMarital(string[] maritalStatusId)
        {
            try
            {
                _maritalStatusDAO = CreateSQLDAO();
                return _maritalStatusDAO.deleteMarital(maritalStatusId);
            }
            catch (Exception e)
            {
                return false;
            }            
        }

        public bool checkMaritalExist(string maritalStatusId, string code, string name)
        {
            try
            {
                _maritalStatusDAO = CreateSQLDAO();
                return _maritalStatusDAO.checkMaritalExist(maritalStatusId, code, name);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
